package cn.qfei.qiyuesuo.controller;

import cn.qfei.qiyuesuo.common.ContractConstant;
import cn.qfei.qiyuesuo.common.enums.ErrorCode;
import cn.qfei.qiyuesuo.common.until.QiyuesuoCallbackUtils;
import cn.qfei.qiyuesuo.domain.WhiteIpData;
import cn.qfei.qiyuesuo.service.FeishuNoticeService;
import cn.qfei.qiyuesuo.service.QiyuesuoApiService;
import cn.qfei.qiyuesuo.service.WhiteIpService;
import cn.qfei.qiyuesuo.service.impl.HankouDataServiceImpl;
import cn.qfei.qiyuesuo.vo.HankouDataSendVo;
import cn.qfei.qiyuesuo.vo.qiyuesuo.AccessResult;
import cn.qfei.qiyuesuo.vo.qiyuesuo.CallbackData;
import cn.qfei.qiyuesuo.vo.qiyuesuo.CallbackValidateResult;
import cn.qfei.qiyuesuo.vo.qiyuesuo.QysContractNoticeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 开开下签章
 */
@RestController
@RequestMapping("/qys")
@Slf4j
public class QiyuesuoNoticeController {
    @Autowired
    private QiyuesuoApiService qiyuesuoApiService;
    @Autowired
    private HankouDataServiceImpl hankouDataService;
    @Autowired
    private FeishuNoticeService feishuNoticeService;
//    @PostMapping("/notic/send")
//    public String getTriggers(@RequestBody HankouDataSendVo vo) {
//        hankouDataService.saveResLog(vo);
//        List<WhiteIpData> list= whiteIpService.getIpList();
//        System.out.println(list);
//       log.info("就来了");
//        return "start";
//    }

    /**
     * 审批
     * 企业锁文件上传
     * @param callbackData
     * @return
     */
    @PostMapping("/send")
    public AccessResult callbackApproval(@RequestBody CallbackData callbackData) {
        CallbackValidateResult validateResult =  qiyuesuoApiService.callbackValidateResult(callbackData);
//        if (!validateResult.isValid()) {
//            return AccessResult.newErrorMessage(10000, validateResult.getMessage());
//        }
         validateResult =new CallbackValidateResult();
                // 回调具体信息
        String plainText = validateResult.getPlainText();
        QysContractNoticeVo vo=qiyuesuoApiService.getQysContractNoticeVo(plainText);
        vo=new QysContractNoticeVo();

//        getPreSignurl


        ErrorCode errorCode= feishuNoticeService.updateQysNotice(vo);
        // 异步处理业务逻辑
        log.info("接收到电子签章系统回调，回调内容【{}】", plainText);
        return AccessResult.newSuccessMessage("回调成功");
    }

    /**
     * 合同
     * @param callbackData
     * @return
     */
//    @PostMapping("/ht/notic/send")
//    public AccessResult callbackContract(@RequestBody CallbackData callbackData) {
//        CallbackValidateResult validateResult =  qiyuesuoApiService.callbackValidateResult(callbackData);
//        if (!validateResult.isValid()) {
//            return AccessResult.newErrorMessage(10000, validateResult.getMessage());
//        }
//        // 回调具体信息
//        String plainText = validateResult.getPlainText();
//        QysContractNoticeVo vo=qiyuesuoApiService.getQysContractNoticeVo(plainText);
//
//        ErrorCode errorCode= hankouDataService.updateContractPlace(vo);
//        // 异步处理业务逻辑
//        log.info("接收到电子签章系统回调，回调内容【{}】", plainText);
//        return AccessResult.newSuccessMessage("回调成功");
//    }

}
